<template>
  <div class="m-tradedetail">
    <h1>{{$t('txDetail.title')}}</h1>
    <div class="not-found table-shadow" v-if="txNotFound">
      <p>
        {{$t('components.noMsg')}}，
        <span
          @click="txNotFound=false;getTradeDetail(hash)"
        >{{$t('components.repeat')}}</span>
      </p>
    </div>
    <h2>{{$t('blockDetail.general')}}</h2>
    <!-- 表格部分 -->
    <div class="data-table table-shadow" v-if="!txNotFound">
      <div class="item line flex-left">
        <label>{{$t('home.txHash')}}</label>
        <div class="item-text">
          <span>{{hash|filterHash}}</span>
          <i
            class="iconfont iconfuzhi"
            v-clipboard:copy="hash"
            v-clipboard:success="success"
            v-clipboard:error="error"
          ></i>
        </div>
      </div>
      <div class="item flex-left">
        <label>{{$t('txDetail.status')}}</label>
        <div class="item-text">
          <div :class="['status flex-center',trade.state===1?'success':'faild']">
            <i class="iconfont" :class="trade.state===1?'iconchenggong':'iconcuowu'"></i>
            {{trade.txt}}
          </div>
        </div>
      </div>
      <div class="item line flex-left">
        <label>{{$t('blockDetail.title')}}</label>
        <div class="item-text">
          <router-link :to="`/blockDetail?height=${trade.height}`" class="light">{{trade.height}}</router-link>
        </div>
      </div>
      <div class="item flex-left">
        <label>{{$t('trade.time')}} (UTC+8)</label>
        <div class="item-text">{{trade.blockTime|caculateTime}}</div>
      </div>
      <div class="item line flex-left">
        <label>{{$t('trade.sender')}}</label>
        <div class="item-text">
          <router-link
            :to="`/address?address=${trade.fromAddr}`"
            class="light"
          >{{trade.fromAddr|filterHash}}</router-link>
        </div>
      </div>
      <div class="item flex-left">
        <label>{{$t('trade.receiver')}}</label>
        <div class="item-text">
          <router-link
            :to="`/address?address=${trade.tx.to}`"
            class="light"
          >{{trade.tx.to|filterHash}}</router-link>
        </div>
      </div>
      <div class="item line flex-left">
        <label>{{$t('txDetail.value')}}</label>
        <div class="item-text">{{trade|TradeValue}}</div>
      </div>
      <div class="item flex-left">
        <label>{{$t('trade.fee')}}</label>
        <div class="item-text">{{trade.tx.fee|filterFee}}</div>
      </div>
      <div class="item line flex-left">
        <label>{{$t('txDetail.random')}}</label>
        <div class="item-text">{{String(trade.tx.nonce)}}</div>
      </div>
      <div class="item flex-left">
        <label>{{$t('txDetail.execer')}}</label>
        <div class="item-text">{{trade.tx.execer}}</div>
      </div>
      <div class="item line flex-left">
        <label>{{$t('trade.func')}}</label>
        <div class="item-text">{{trade.actionName==='unknown'? 'none':trade.actionName}}</div>
      </div>
      <div class="item flex-left">
        <label>{{$t('txDetail.txType')}}</label>
        <div class="item-text">{{trade|tradeGroup}}</div>
      </div>
      <div class="markdown-data" v-if="trade.tx.execer==='user.write'">
        <markdown :content="markdownTxt"></markdown>
      </div>
      <div class="area line" v-if="trade.tx.execer!=='user.write'">
        <label>{{$t('txDetail.inData')}}</label>
        <div class="item-text flex-right">
          <pre class="preTxt" contenteditable="true"> 
            <code>{{trade.tx|decodeTransferNote}}</code>
          </pre>
        </div>
      </div>
      <div class="area line" v-if="trade.tx.execer!=='user.write'">
        <label>{{$t('txDetail.outData')}}</label>
        <div class="item-text flex-right">
          <pre class="preTxt" contenteditable="true">
            <code>{{trade.receipt}}</code>
          </pre>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import tradeDetail from "@/mixins/TradeDetail/tradedetail.js";
export default {
  components: {
    markdown: () => import("@/components/markdown")
  },
  mixins: [tradeDetail]
};
</script>

<style lang="scss" scoped>
.m-tradedetail {
  padding: 10px 20px;
  h1,
  h2 {
    color: #53657a;
    font-size: 14px;
    font-family: PingFangSC-Semibold;
  }
  h2 {
    color: $black;
    margin-top: 20px;
  }
  .not-found {
    margin-top: 10px;
    padding: 10px;
    text-align: center;
    background: $white;
    span {
      color: #366c96;
    }
  }
  .data-table {
    background: $white;
    padding: 10px;
    margin-top: 10px;
    color: $black;
    .item {
      line-height: 37px;
      label {
        min-width: 120px;
        display: flex;
        justify-content: left;
        align-items: center;
        i {
          margin-right: 7px;
          color: #b5d2e9;
        }
      }
      i.iconfuzhi {
        color: $blue;
        margin-left: 15px;
      }
      .status {
        display: inline-block;
        // height: 25px;
        line-height: 25px;
        padding: 0px 10px;
        border-radius: 3px;
        font-size: 11px;
        i {
          font-size: 12px;
        }
      }
      .success {
        background: rgba(0, 201, 167, 0.1);
        color: #00c9a7;
      }
      .faild {
        background: rgba(193, 56, 56, 0.1);
        color: #c13838;
      }
    }
    .area {
      label {
        line-height: 37px;
      }
      i {
        margin-right: 7px;
        color: #b5d2e9;
      }
      .preTxt {
        height: 200px;
        padding: 15px;
        font-family: Verdana;
        overflow-y: auto;
        vertical-align: middle;
        width: 290px;
        word-break: break-all;
      }
      code {
        line-height: 1.38;
        margin-left: -49px;
        font-family: "Verdana";
      }
      .preTxt {
        border: 1px solid #ebeff1;
        cursor: default;
        overflow-y: scroll;
        // IE下隐藏
        -ms-overflow-style: none;
        // 火狐浏览器隐藏
        scrollbar-color: transparent transparent;
      }
      .preTxt::-webkit-scrollbar {
        width: 5px;
        height: 5px;
        background: #e0e3e6;
      }
      .preTxt::-webkit-scrollbar-thumb {
        border-radius: 50px;
        background: $blue;
      }
    }
  }
}
</style>